package com.androidhive.androidlistview;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class FarmerMenu extends ListActivity {
	public final static String action=new String();
	SessionManager session;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        session = new SessionManager(getApplicationContext());
        
        // storing string resources into Array
        String[] farmer_menu = getResources().getStringArray(R.array.farmer_menu);
      
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, farmer_menu));
        
        ListView lv = getListView();
        
        // listening to single list item on click
        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
        	  
        	  // selected item 
        	  String product = ((TextView) view).getText().toString();
        	  if(product.equalsIgnoreCase("Logout")){
        		  session.logoutUser();
        	  // Launching new Activity on selecting single List Item
        	  Intent i = new Intent(getApplicationContext(), AppEntrance.class);
        	  // sending data to new activity
        	  i.putExtra("product", product+"rk");
        	  startActivity(i);
        	
          }
        	  if(product.equalsIgnoreCase("Add Crops")){
            	 //  Launching new Activity on selecting single List Item
            	  Intent i = new Intent(getApplicationContext(), AddCrops.class);
            	  // sending data to new activity
            	//  i.putExtra(action, product+"rk");
            	  startActivity(i);
            	
              }  
        	  if(product.equalsIgnoreCase("View All Bids")){
             	 //  Launching new Activity on selecting single List Item
             	  Intent i = new Intent(getApplicationContext(), FarmerCrops.class);
             	  Log.d("started ","FarmerCrops ");
             	  // sending data to new activity
             	//  i.putExtra("product", "View");
             	  startActivity(i);
             	
               }  
        	  if(product.equalsIgnoreCase("Search Crops By Name")){
             	 //  Launching new Activity on selecting single List Item
             	  Intent i = new Intent(getApplicationContext(), SingleListItem.class);
             	  // sending data to new activity
             	//  i.putExtra("product", product+"rk");
             	  startActivity(i);
             	
               }  
        	  if(product.equalsIgnoreCase("Search Crops By State")){
              	 //  Launching new Activity on selecting single List Item
              	  Intent i = new Intent(getApplicationContext(), StateWiseSearch.class);
              	  // sending data to new activity
              	//  i.putExtra("product", product+"rk");
              	  startActivity(i);
              	
                }  
        	  if(product.equalsIgnoreCase("View All Crops")){
               	 //  Launching new Activity on selecting single List Item
               	  Intent i = new Intent(getApplicationContext(), ListViewCheckboxesActivity.class);
               	  // sending data to new activity
               	//  i.putExtra("product", product+"rk");
               	  startActivity(i);
               	
                 }  
        	  if(product.equalsIgnoreCase("Delete Crops")){
                	 //  Launching new Activity on selecting single List Item
                	  Intent i = new Intent(getApplicationContext(), FarmerDeleteCrop.class);
                	  // sending data to new activity
                	//  i.putExtra(action, "Delete");
                	  startActivity(i);
                	
                  }  
        	  if(product.equalsIgnoreCase("View Profile")){
              	 //  Launching new Activity on selecting single List Item
              	  Intent i = new Intent(getApplicationContext(), FViewprofile.class);
              	  // sending data to new activity
              	//  i.putExtra("product", product+"rk");
              	  startActivity(i);
              	
                }  
          
          
          }
        });
    }
}